<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>v-if指令</title>
  </head>
  <body>
    <!-- v-for:根据数据生成列表结构 -->
    <div id="app">
      <input type="button" value="添加一线城市" @click="add" />
      <input type="button" value="移除一线城市" @click="remove" />
      <ul>
        <li v-for="(item,index) in arr">一线城市{{index+1}}：{{item}}</li>
      </ul>
      <h1 v-for="(item,index) in objArr">{{index+1}}{{ item.name }}</h1>
    </div>
    <!-- 开发环境版本，包含了有帮助的命令行警告 -->
    <script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
    <script>
      var app = new Vue({
        el: "#app",
        data: {
          arr: ["北京", "上海", "深圳", "广州"],
          objArr: [{ name: "AAA" }, { name: "BBB" }, { name: "CCC" }],
        },
        methods: {
          add: function () {
            this.arr.push("武汉");
          },
          remove: function () {
            this.arr.shift();
          },
        },
      });
    </script>
  </body>
</html>
